package com.xinqi.modules.databank.v2.controller.common.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.modules.databank.dto.req.CourseResourceRemoveDTO;
import com.xinqi.modules.databank.dto.req.ResourceBaseQueryDTO;
import com.xinqi.modules.databank.dto.rsp.CourseResourceBaseResultDTO;
import com.xinqi.modules.databank.v2.service.common.CourseResourceBaseService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 资料库APP公共接口
 * @author: dzy
 * @date: 2023/07/14
 */
@Tag(name = "资料库APP公共接口", description = "资料库APP公共接口")
@RestController
@RequestMapping("/app/base/resource")
@RequiredArgsConstructor
@Validated
public class ResourceBaseAppController {

    private final CourseResourceBaseService courseResourceBaseService;

    /**
     * 老师端查询发布资料库
     * @Author dzy
     * @Date 15:02 2023/3/16
     * @Return
     * @Exception
     */
    @GetMapping("/release/page")
    public R<PageInfo<CourseResourceBaseResultDTO>> teacherReleaseInteractiveCourse(ResourceBaseQueryDTO queryDTO){
        PageInfo<CourseResourceBaseResultDTO> res = courseResourceBaseService.teacherReleasePage(queryDTO);
        return R.ok(res);
    }

    /**
     * 老师端查询未发布资料库
     * @Author dzy
     * @Date 2023/07/14
     * @Return
     * @Exception
     */
    @GetMapping("/unrelease/page")
    public R<PageInfo<CourseResourceBaseResultDTO>> teacherUnreleaseInteractiveCourse(@Validated ResourceBaseQueryDTO queryDTO){
        PageInfo<CourseResourceBaseResultDTO> res = courseResourceBaseService.teacherUnreleasePage(queryDTO);
        return R.ok(res);
    }

    /**
     * 学生查询资料库
     * @Author dzy
     * @Date 2023/07/14
     * @Description
     * @Return
     * @Exception
     */
    @GetMapping("/student/page")
    public R<PageInfo<CourseResourceBaseResultDTO>> studentGetInteractiveCourse(@Validated ResourceBaseQueryDTO queryDTO){
        PageInfo<CourseResourceBaseResultDTO> res = courseResourceBaseService.studentPage(queryDTO);
        return R.ok(res);
    }

    /**
     * 删除资料库数据
     * @Author dzy
     * @Date 2023/07/14
     * @Description
     * @Return
     * @Exception
     */
    @DeleteMapping("/remove")
    public R<String> remove(@RequestBody @Validated CourseResourceRemoveDTO dto){
        if (courseResourceBaseService.deletedByIds(dto.getIdList())) {
            return R.ok(MessageUtils.message("common.remove.success"));
        } else {
            return R.fail(MessageUtils.message("common.remove.fail"));
        }
    }

}
